import { _decorator, AudioClip, Component, Node } from 'cc';
import { SSS_Consts } from "../Data/SSS_Consts";
import { bdlMgr } from "../Manager/BundleManager_S";
import SSS_GameEventManager, { SS_GameEventData } from "../Manager/SSS_GameEventManager";
import { SSS_AudioManager } from '../Manager/SSS_AudioManager';

const { ccclass, property } = _decorator;

@ccclass('WinPanel')
export default class WinPanel extends Component {
    public static Instance: WinPanel;
    @property(Node)
    public Button_menu: Node | null = null;
    @property(Node)
    public Button_next: Node | null = null;
    //    // @property(Node)
    //    // public Button_close: Node = null;
    //    // @property(Node)
    //    // public Button_replay: Node = null;
    onLoad() {
        WinPanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();

        // let audio_root = `audio/level complete`;

        let r = 4;
        let audio_root = `audio/Win sound/Win sound ${r}`;
        console.log(`audio_root`, audio_root);

        bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
            SSS_AudioManager.Instance.playSFX(res, false);
        });
    }
    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    async Refresh() {

    }
    AddListener() {
        this.Button_menu.on(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_next.on(Node.EventType.TOUCH_END, this.On_Button_next, this);

        // this.Button_close.on(Node.EventType.TOUCH_END, this.On_Button_close, this);
        // this.Button_replay.on(Node.EventType.TOUCH_END, this.On_Button_replay, this);
    }
    RemoveListener() {
        this.Button_menu.off(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_next.off(Node.EventType.TOUCH_END, this.On_Button_next, this);

        // this.Button_close.off(Node.EventType.TOUCH_END, this.On_Button_close, this);
        // this.Button_replay.off(Node.EventType.TOUCH_END, this.On_Button_replay, this);
    }
    On_Button_menu() {
        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Menu);
        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_next() {
        // console.log(`On_Button_next`);

        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Next_Level);
        SSS_AudioManager.PlayButtonAudio();

        // DanCiPeiDui.Instance.下一关();
    }

    // //    // On_Button_close() {
    // //    //     this.ShowOff();
    // //    //     // director.loadScene("DanCiPeiDuiScene");
    // //    // }
    // //    // On_Button_replay() {
    // //    //     this.ShowOff();
    // //    //     // director.loadScene("DanCiPeiDuiScene");
    // //    //     SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Next_Level);
    // //    // }
    // }
}